package de.slowlog;

public class SlowLogController {

	public SlowLogEntry getMaxQueryTime(SlowLog slowLog) {
		double max = Double.MIN_VALUE;
		SlowLogEntry result = null;
		for (SlowLogEntry entry : slowLog.getEntries()) {
			if (entry.getQueryTime() > max) {
				result = entry;
				max = result.getQueryTime();
			}
		}

		return result;
	}

	public SlowLogEntry getMinQueryTime(SlowLog slowLog) {
		double min = Double.MAX_VALUE;
		SlowLogEntry result = null;
		for (SlowLogEntry entry : slowLog.getEntries()) {
			if (entry.getQueryTime() < min) {
				result = entry;
				min = result.getQueryTime();
			}
		}

		return result;
	}

	public double getMeanQueryTime(SlowLog slowLog) {
		double sum = 0;
		for (SlowLogEntry entry : slowLog.getEntries()) {
			sum += entry.getQueryTime();
		}

		return sum / slowLog.getEntries().size();
	}

}
